package org.example.springboot.mapper;


import org.apache.ibatis.annotations.*;
import org.example.springboot.entity.User;

import java.util.List;

@Mapper
public interface UserMapper {


    @Select("SELECT * FROM user WHERE username LIKE CONCAT ('%', #{username}, '%') LIMIT #{offset}, #{pageSize} ")
    List<User> getUsersByPage(@Param("pageSize") int pageSize,@Param("offset") int offset, @Param("username") String username);

    @Select("SELECT COUNT(*) FROM user WHERE username LIKE CONCAT ('%', #{username}, '%')")
    Integer getUserCount(@Param("username") String username);

    @Delete("DELETE FROM user WHERE account = #{account}")
    void deleteUserByAccount(@Param("account") String account);

    @Insert("INSERT INTO user (account, username, name, phone_number, city, avatar) " +
            "VALUES (#{account}, #{username}, #{name}, #{phone_number}, #{city}, #{avatar})")
    void insertUser(User user);

    @Select("SELECT * FROM user WHERE account = #{account}")
    User selectByAccount(String account);

    @Update("UPDATE user SET username = #{username}, name = #{name}, phone_number = #{phone_number}, city = #{city}, avatar = #{avatar} WHERE account = #{account}")
    void updateUser(User user);

    @Update("UPDATE user SET password = #{password} WHERE account = #{account}")
    void updatePassword(String account, String password);
}
